from tortoise.models import Model
from tortoise import fields

class Role(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=50, unique=True)

    users: fields.ReverseRelation["User"]

class User(Model):
    id = fields.IntField(pk=True)
    username = fields.CharField(max_length=100, unique=True, description="用户名/邮箱")
    hashed_password = fields.CharField(max_length=128)
    role = fields.ForeignKeyField("models.Role", related_name="users")

    class Meta:
        table = "user"
